(* Content-type: application/mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 7.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       145,          7]
NotebookDataLength[     11228,        342]
NotebookOptionsPosition[     10351,        307]
NotebookOutlinePosition[     10687,        322]
CellTagsIndexPosition[     10644,        319]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell["\<\
This is used to calculate the thermal averaging of S-W model. Such effect \
should be considered for superparamagnetism.\
\>", "Text",
 CellChangeTimes->{{3.51759845274025*^9, 3.517598491583536*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"Etot", "=", 
   RowBox[{
    RowBox[{
     RowBox[{"-", "A"}], " ", 
     RowBox[{"Cos", "[", "\[Phi]", "]"}]}], "-", " ", 
    RowBox[{
     RowBox[{"Cos", "[", 
      RowBox[{"\[Theta]", "-", "\[Phi]"}], "]"}], "^", "2"}]}]}], 
  ";"}]], "Input"],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{"Aout", "=", 
   RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Qout", "=", 
   RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Tout", "=", 
   RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Pout", "=", 
   RowBox[{"{", "}"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Alist", "=", 
   RowBox[{"Join", "[", 
    RowBox[{
     RowBox[{"Range", "[", 
      RowBox[{"0", ",", "1", ",", "0.03"}], "]"}], ",", 
     RowBox[{"Range", "[", 
      RowBox[{"1", ",", "2", ",", "0.1"}], "]"}], ",", 
     RowBox[{"Range", "[", 
      RowBox[{"2.3", ",", "5", ",", "0.3"}], "]"}], ",", 
     RowBox[{"Range", "[", 
      RowBox[{"6", ",", "10", ",", "1"}], "]"}]}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"thetalist", "=", 
   RowBox[{"N", "[", 
    RowBox[{"Range", "[", 
     RowBox[{"0", ",", 
      RowBox[{"\[Pi]", "/", "2"}], ",", 
      RowBox[{"\[Pi]", "/", "50"}]}], "]"}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Qlist", "=", 
   RowBox[{"Join", "[", 
    RowBox[{
     RowBox[{"Range", "[", 
      RowBox[{"0.01", ",", "0.5", ",", "0.03"}], "]"}], ",", 
     RowBox[{"Range", "[", 
      RowBox[{"0.52", ",", "1", ",", "0.04"}], "]"}], ",", 
     RowBox[{"Range", "[", 
      RowBox[{"1.1", ",", "2", ",", "0.1"}], "]"}], ",", 
     RowBox[{"Range", "[", 
      RowBox[{"2", ",", "5", ",", "1"}], "]"}]}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{"Timing", "[", "\[IndentingNewLine]", 
  RowBox[{"For", "[", 
   RowBox[{
    RowBox[{"i", "=", "1"}], ",", 
    RowBox[{"i", "\[LessEqual]", 
     RowBox[{"Length", "[", "Alist", "]"}]}], ",", 
    RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", 
    RowBox[{"For", "[", 
     RowBox[{
      RowBox[{"j", "=", "1"}], ",", 
      RowBox[{"j", "\[LessEqual]", 
       RowBox[{"Length", "[", "thetalist", "]"}]}], ",", 
      RowBox[{"j", "++"}], ",", "\[IndentingNewLine]", 
      RowBox[{"For", "[", 
       RowBox[{
        RowBox[{"k", "=", "1"}], ",", 
        RowBox[{"k", "\[LessEqual]", 
         RowBox[{"Length", "[", "Qlist", "]"}]}], ",", 
        RowBox[{"k", "++"}], ",", "\[IndentingNewLine]", 
        RowBox[{
         RowBox[{"Evalue", "=", 
          RowBox[{"Evaluate", "[", 
           RowBox[{"Etot", "/.", 
            RowBox[{"{", 
             RowBox[{
              RowBox[{"A", "\[Rule]", " ", 
               RowBox[{"Alist", "[", 
                RowBox[{"[", "i", "]"}], "]"}]}], ",", 
              RowBox[{"\[Theta]", "\[Rule]", 
               RowBox[{"thetalist", "[", 
                RowBox[{"[", "j", "]"}], "]"}]}]}], "}"}]}], "]"}]}], ";", 
         "\[IndentingNewLine]", 
         RowBox[{"Pave", "=", 
          RowBox[{
           RowBox[{"NIntegrate", "[", 
            RowBox[{
             RowBox[{
              RowBox[{"Exp", "[", 
               RowBox[{
                RowBox[{"-", "Evalue"}], "/", 
                RowBox[{"Qlist", "[", 
                 RowBox[{"[", "k", "]"}], "]"}]}], "]"}], "*", "\[Phi]", "*", 
              
              RowBox[{"Sin", "[", "\[Phi]", "]"}]}], ",", 
             RowBox[{"{", 
              RowBox[{"\[Phi]", ",", "0", ",", "\[Pi]"}], "}"}]}], "]"}], "/", 
           RowBox[{"NIntegrate", "[", 
            RowBox[{
             RowBox[{
              RowBox[{"Exp", "[", 
               RowBox[{
                RowBox[{"-", "Evalue"}], "/", 
                RowBox[{"Qlist", "[", 
                 RowBox[{"[", "k", "]"}], "]"}]}], "]"}], "*", 
              RowBox[{"Sin", "[", "\[Phi]", "]"}]}], ",", 
             RowBox[{"{", 
              RowBox[{"\[Phi]", ",", "0", ",", "\[Pi]"}], "}"}]}], "]"}]}]}], 
         ";", "\[IndentingNewLine]", 
         RowBox[{"Aout", "=", 
          RowBox[{"Append", "[", 
           RowBox[{"Aout", ",", 
            RowBox[{"Alist", "[", 
             RowBox[{"[", "i", "]"}], "]"}]}], "]"}]}], ";", 
         "\[IndentingNewLine]", 
         RowBox[{"Tout", "=", 
          RowBox[{"Append", "[", 
           RowBox[{"Tout", ",", 
            RowBox[{"N", "[", 
             RowBox[{"thetalist", "[", 
              RowBox[{"[", "j", "]"}], "]"}], "]"}]}], "]"}]}], ";", 
         "\[IndentingNewLine]", 
         RowBox[{"Qout", "=", 
          RowBox[{"Append", "[", 
           RowBox[{"Qout", ",", 
            RowBox[{"Qlist", "[", 
             RowBox[{"[", "k", "]"}], "]"}]}], "]"}]}], ";", 
         "\[IndentingNewLine]", 
         RowBox[{"Pout", "=", 
          RowBox[{"Append", "[", 
           RowBox[{"Pout", ",", "Pave"}], "]"}]}], ";"}]}], 
       "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], 
   "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", 
  "]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"out", "=", 
   RowBox[{"Transpose", "[", 
    RowBox[{"{", 
     RowBox[{"Aout", ",", "Tout", ",", "Qout", ",", "Pout"}], "}"}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{"Export", "[", 
  RowBox[{"\"\<SW_thermal.dat\>\"", ",", "out"}], "]"}]}], "Input",
 CellChangeTimes->{{3.517598920267149*^9, 3.517599018068911*^9}, {
   3.5175990487760878`*^9, 3.5175990988181868`*^9}, {3.51759913701939*^9, 
   3.517599262171022*^9}, {3.517599333470888*^9, 3.517599381602882*^9}, {
   3.517599411863039*^9, 3.517599498339238*^9}, {3.51759953694807*^9, 
   3.51759964185988*^9}, {3.5175997448306*^9, 3.517599820712782*^9}, {
   3.517599854380414*^9, 3.517599865280828*^9}, {3.517600085487626*^9, 
   3.517600087657078*^9}, {3.517600663848728*^9, 3.517600671285122*^9}, {
   3.517600828584504*^9, 3.51760083290195*^9}, {3.5176011884357653`*^9, 
   3.5176012177838573`*^9}, {3.517601281804435*^9, 3.517601318568116*^9}, {
   3.5176014189833717`*^9, 3.517601419252109*^9}, {3.5176016009028397`*^9, 
   3.517601635809688*^9}, 3.517602531944474*^9, 3.5176028360646152`*^9}],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"1219.463613`", ",", "Null"}], "}"}]], "Output",
 CellChangeTimes->{3.5176015379237013`*^9, 3.517601741445304*^9, 
  3.517604153408883*^9}],

Cell[BoxData["\<\"SW_thermal.dat\"\>"], "Output",
 CellChangeTimes->{3.5176015379237013`*^9, 3.517601741445304*^9, 
  3.5176041585452213`*^9}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"A1", "=", 
  RowBox[{"Integrate", "[", 
   RowBox[{
    RowBox[{
     RowBox[{"Exp", "[", 
      RowBox[{"P", " ", 
       RowBox[{"Cos", "[", "\[Phi]", "]"}]}], "]"}], "\[Phi]", " ", 
     RowBox[{"Sin", "[", "\[Phi]", "]"}]}], ",", 
    RowBox[{"{", 
     RowBox[{"\[Phi]", ",", "0", ",", "\[Pi]"}], "}"}], ",", 
    RowBox[{"Assumptions", "\[Rule]", 
     RowBox[{"P", ">", "0"}]}]}], "]"}]}]], "Input",
 CellChangeTimes->{{3.5176478497969847`*^9, 3.5176478811661177`*^9}, {
  3.517647944098385*^9, 3.517647998624887*^9}, {3.517648062307652*^9, 
  3.517648063680818*^9}}],

Cell[BoxData[
 FractionBox[
  RowBox[{
   SuperscriptBox["\[ExponentialE]", 
    RowBox[{"-", "P"}]], " ", "\[Pi]", " ", 
   RowBox[{"(", 
    RowBox[{
     RowBox[{"-", "1"}], "+", 
     RowBox[{
      SuperscriptBox["\[ExponentialE]", "P"], " ", 
      RowBox[{"BesselI", "[", 
       RowBox[{"0", ",", "P"}], "]"}]}]}], ")"}]}], "P"]], "Output",
 CellChangeTimes->{
  3.517647902363863*^9, 3.517647946614839*^9, {3.5176479937738953`*^9, 
   3.517648000515325*^9}, 3.51764806919526*^9}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"A2", "=", 
  RowBox[{"Integrate", "[", 
   RowBox[{
    RowBox[{
     RowBox[{"Exp", "[", 
      RowBox[{"P", " ", 
       RowBox[{"Cos", "[", "\[Phi]", "]"}]}], "]"}], " ", 
     RowBox[{"Sin", "[", "\[Phi]", "]"}]}], ",", 
    RowBox[{"{", 
     RowBox[{"\[Phi]", ",", "0", ",", "\[Pi]"}], "}"}], ",", 
    RowBox[{"Assumptions", "\[Rule]", 
     RowBox[{"P", ">", "0"}]}]}], "]"}]}]], "Input",
 CellChangeTimes->{{3.5176480181373453`*^9, 3.5176480217159758`*^9}, {
  3.5176480662544947`*^9, 3.517648066977315*^9}}],

Cell[BoxData[
 FractionBox[
  RowBox[{"2", " ", 
   RowBox[{"Sinh", "[", "P", "]"}]}], "P"]], "Output",
 CellChangeTimes->{3.517648023341448*^9, 3.5176480705513687`*^9}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"PHI", "=", 
  RowBox[{
   RowBox[{"Simplify", "[", 
    RowBox[{"A1", "/", "A2"}], "]"}], "/.", 
   RowBox[{"P", "\[Rule]", 
    RowBox[{"A", "/", "Q"}]}]}]}]], "Input",
 CellChangeTimes->{{3.5176480719439287`*^9, 3.5176481034513807`*^9}}],

Cell[BoxData[
 FractionBox[
  RowBox[{"\[Pi]", " ", 
   RowBox[{"(", 
    RowBox[{
     RowBox[{"-", "1"}], "+", 
     RowBox[{
      SuperscriptBox["\[ExponentialE]", 
       RowBox[{"A", "/", "Q"}]], " ", 
      RowBox[{"BesselI", "[", 
       RowBox[{"0", ",", 
        FractionBox["A", "Q"]}], "]"}]}]}], ")"}]}], 
  RowBox[{
   RowBox[{"-", "1"}], "+", 
   SuperscriptBox["\[ExponentialE]", 
    FractionBox[
     RowBox[{"2", " ", "A"}], "Q"]]}]]], "Output",
 CellChangeTimes->{3.517648104226844*^9}]
}, Open  ]],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"PHI", "/.", 
  RowBox[{"{", 
   RowBox[{
    RowBox[{"A", "\[Rule]", "0.3"}], ",", 
    RowBox[{"Q", "\[Rule]", "10"}]}], "}"}]}]], "Input",
 CellChangeTimes->{{3.51764811905857*^9, 3.517648149019227*^9}}],

Cell[BoxData["1.559016016967317`"], "Output",
 CellChangeTimes->{{3.517648137674672*^9, 3.517648149553211*^9}}]
}, Open  ]]
},
WindowSize->{866, 521},
WindowMargins->{{103, Automatic}, {Automatic, 1}},
FrontEndVersion->"7.0 for Linux x86 (64-bit) (October 28, 2009)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[545, 20, 209, 4, 31, "Text"],
Cell[757, 26, 283, 10, 32, "Input"],
Cell[CellGroupData[{
Cell[1065, 40, 5879, 148, 561, "Input"],
Cell[6947, 190, 178, 4, 31, "Output"],
Cell[7128, 196, 142, 2, 31, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[7307, 203, 598, 15, 32, "Input"],
Cell[7908, 220, 488, 14, 51, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[8433, 239, 541, 14, 32, "Input"],
Cell[8977, 255, 169, 4, 47, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[9183, 264, 263, 7, 32, "Input"],
Cell[9449, 273, 506, 17, 63, "Output"]
}, Open  ]],
Cell[CellGroupData[{
Cell[9992, 295, 229, 6, 32, "Input"],
Cell[10224, 303, 111, 1, 31, "Output"]
}, Open  ]]
}
]
*)

(* End of internal cache information *)
